package qsoft.omanga.ui;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

/**
 * 
 * @author sontt
 * 
 */
public class MainActivity extends TabActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TabHost tabHost = getTabHost();
        tabHost.addTab(createTab(HomeActivity.class, "Home",
                R.drawable.btn_home));
        tabHost.addTab(createTab(RankingActivity.class, "Ranking",
                R.drawable.btn_ranking));
        tabHost.addTab(createTab(ListAllMangaActivity.class, "All",
                R.drawable.btn_list));
        tabHost.addTab(createTab(WebViewNoticeSupport.class, "Notice",
                R.drawable.btn_notice));
        tabHost.addTab(createTab(InformationActivity.class, "Info",
                R.drawable.btn_info));

        tabHost.setCurrentTab(1);
    }

    /**
     * 
     * @param intentClass
     *            Class<?>
     * @param tag
     *            String
     * @param drawable
     *            int
     * @return TabSpec
     */
    private TabSpec createTab(Class<?> intentClass, String tag, int drawable) {
        Intent intent = new Intent().setClass(this, intentClass);

        View tabWidget = LayoutInflater.from(getTabHost().getContext())
                .inflate(R.layout.tabwidget, null);

        ImageView imgView = ((ImageView) tabWidget.findViewById(R.id.tab_icon));
        imgView.setImageResource(drawable);

        TabSpec tabSpec = getTabHost().newTabSpec(tag);
        tabSpec.setContent(intent);
        tabSpec.setIndicator(tabWidget);
       
        return tabSpec;
    }
}
